<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Redux</title>
  </head>
  <body>
    <button>+</button>
    <span></span>
    <button>-</button>
    <script src="./myRedux.js"></script>
    <script>
      // 增强dispatch 实际上就是这样演变成中间件的
      function enhancer(createStore){
        return function(reducer, preloadedState){
          var store = createStore(reducer, preloadedState)
          var dispatch = store.dispatch;
          function _dispatch(action){
            if(typeof action === 'function'){
              return action(dispatch)
            }
            dispatch(dispatch)
          }
          return {
            ...store,
            dispatch:_dispatch
          };
        }
      }
      function reducer(state, action) {
        switch (action.type) {
          case "increment":
            return state + 1;
          case "decrement":
            return state - 1;
          default:
            return state;
        }
      }
      // 创建store
      var store = createStore(reducer, 0);
      console.log( isPlainObject({}))
      console.log( isPlainObject([]))
    </script>
  </body>
</html>
